import os
import cv2
import numpy as np

# 输入和输出路径 context59
# maskclip_dir = "/space0/liangc/code/study/OVSS/MaskCLIP/output/voc59"
# ours_dir = "/space0/liangc/code/study/OVSS/clip_dinoiser/outputs/demo/voc59_dclip"
# output_dir = "/space0/liangc/code/study/OVSS/clip_dinoiser/outputs/demo/voc59_compare"

# cityscapes
maskclip_dir = "/space0/liangc/code/study/OVSS/MaskCLIP/output/city_maskclip/frankfurt"
ours_dir = "/space0/liangc/code/study/OVSS/clip_dinoiser/outputs/demo/cityscapes_dclip/frankfurt"
output_dir = "/space0/liangc/code/study/OVSS/clip_dinoiser/outputs/demo/cityscapes_compare/frankfurt"

os.makedirs(output_dir, exist_ok=True)

# 获取文件列表，假设两个文件夹内文件名完全一致
file_list = sorted(os.listdir(maskclip_dir))

for file_name in file_list:
    maskclip_path = os.path.join(maskclip_dir, file_name)
    ours_path = os.path.join(ours_dir, file_name)

    # 检查两个文件是否都存在
    if not os.path.exists(maskclip_path) or not os.path.exists(ours_path):
        print(f"文件缺失：{file_name}")
        continue

    # 读取图片
    maskclip_img = cv2.imread(maskclip_path)
    ours_img = cv2.imread(ours_path)

    # 调整为相同大小（取 MaskCLIP 的大小为基准）
    ours_img = cv2.resize(ours_img, (maskclip_img.shape[1], maskclip_img.shape[0]))

    # 水平拼接
    combined_img = np.hstack((maskclip_img, ours_img))

    # 保存拼接图片
    output_path = os.path.join(output_dir, file_name)
    cv2.imwrite(output_path, combined_img)

print("图片对比图生成完毕！")
